package cn.client.data.remoteData

import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.WebSocket
import okhttp3.WebSocketListener
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class WebSocketConfig @Inject constructor(
    private val okHttpClient: OkHttpClient
) {

    // WebSocket URL
    private val baseWebSocketUrl  = "ws://39.106.54.215:8080/chat"

    // 根据用户ID构建WebSocket URL
    fun webSocketUrlWithUid(uid: Int): String {
        return "$baseWebSocketUrl?uid=$uid"
    }


    fun connectWebSocket(url: String, listener: WebSocketListener): WebSocket {
        return okHttpClient.newWebSocket(
            Request.Builder()
                .url(url)
                .build(),
            listener
        )
    }
}